package com.wnhz.work.jy.fragment;


import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.wnhz.work.jy.R;
import com.wnhz.work.jy.activity.IncomeAndExpensesDetailActivity;
import com.wnhz.work.jy.adapter.DetailAdapter;
import com.wnhz.work.jy.adapter.ExpensesFragmentAdapter;
import com.wnhz.work.jy.bean.DetailBean;
import com.wnhz.work.jy.bean.IncomeAndExpensesBean;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 * 收支明细---收入
 */
@ContentView(R.layout.fragment_income)
public class IncomeFragment extends Fragment {
    private View view;
    @ViewInject(R.id.lv_income)
    private ListView lv_income;

    @ViewInject(R.id.include_occupied)
    private View include_occupied;
    @ViewInject(R.id.blank_tv)
    private TextView blank_tv;

    private ExpensesFragmentAdapter mAdapter;
    private List<IncomeAndExpensesBean.ExpendBean> detailList = new ArrayList<>();


    private IncomeAndExpensesDetailActivity activity;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
       /* view = inflater.inflate(R.layout.fragment_income, container, false);
        initData();
        initView();*/
        activity = (IncomeAndExpensesDetailActivity) getActivity();
        return x.view().inject(this, inflater, container);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mAdapter = new ExpensesFragmentAdapter(getActivity(), detailList);
        lv_income.setAdapter(mAdapter);
        setBlank();
    }



    private void setBlank(){
        if (detailList.size() == 0){
            include_occupied.setVisibility(View.VISIBLE);
        }else {
            include_occupied.setVisibility(View.GONE);
        }
    }

   public void setData(){

       detailList.clear();
       detailList.addAll(activity.incomeAndExpensesBean.getIncome());
       mAdapter.notifyDataSetChanged();
       setBlank();
   }
}
